<!DOCTYPE html>
<html>

<head>
	<meta charset="UTF-8">
	<title>设备管理</title>
	<link rel="stylesheet" href="/css/common2.css">
<link rel="stylesheet" href="/scriptZIP/layui.min.css">
	<style>
		.add {
			display: inline-block;
		}

		.search {
			margin-top: -20px;
		}

		.school {
			margin-left: 20px;
			margin-top: 20px;
			display: inline-block;
		}

		.search_img {
			position: absolute;
			margin-top: -20px;
			right: 3%;
		}

		.pagination li a {
			padding: 9px 12px !important;
		}
	</style>
</head>

<body class="main-body">

	<div id="vue-root" style="margin-top: 50px;">
		<div class="add action-buttons" v-if="able.add">
			<a href="device2_item.html" style="color: white">添加设备</a>
		</div>
		<div class="refresh action-buttons" onclick="location.reload()">刷新</div>
		<div class="school">
			<select class="search" v-model="search.schoolId">
				<option :value="undefined">请选择学校</option>
				<option v-for="school in schools" :key="school.id" :value="school.id" v-text="school.name"></option>
			</select>
			<img src="../image/search.png" height="35" width="35" class="search_img" @click="getData0">
		</div>
		<br>

		<div class="table ">
			<table class="table_top">
				<thead>
					<tr>
						<th class="one">
							<input type="checkbox" class="check-box" v-model="all">序号
						</th>
						<th>学校名称</th>
						<th>设备位置</th>
						<th>设备编码</th>
						<th>最新请求时间</th>
						<th v-if="able.edit||able.del">编辑/删除</th>
					</tr>
				</thead>
				<tbody id="list">
					<tr v-for="(device,index) in list" :key="device.id">
						<td>
							<input type="checkbox" class="check-box" v-model="device.checked">
							<span v-text="index+1"></span>
						</td>
						<td v-text="device.schoolName"></td>
						<td v-text="device.name"></td>
						<td class="text" v-text="device.code"></td>

						<td v-text="format(device.latestTime)"></td>
						<td v-if="able.edit||able.del">
							<div class="option">
								<div v-if="able.edit" class="edit-icon option-icon">
									<a :href="'device_item.html?id='+device.id"
										style="position: absolute; left: 20%; top: 30%;">
										<img class="img" height="20" width="20" src="../image/edit.png"
											onmouseover="this.src='../image/edit_light.png'"
											onmouseout="this.src='../image/edit.png'" />
									</a>
								</div>
								<div v-if="able.del" class="delete-icon option-icon" @click="del([device.id])"
									style="right: 20%; top:30%;position: absolute;">
									<img class="img" src="../image/delete.png" height="20" width="20"
										onmouseover="this.src='../image/delete_light.png'"
										onmouseout="this.src='../image/delete.png'" />
								</div>
							</div>
						</td>
					</tr>
				</tbody>
			</table>
		</div>

		<div class="delete" @click="batchDelete" v-if="able.del||total>1">批量删除</div>

		<ul class="pagination" v-if="pages>1">
			<li>
				<a v-if="pageNum!=1" @click="pageNum=1">«</a>
				<a class="pages-jump" v-if="pageNum!=1" @click="pageNum--">‹</a>
				<a v-text="pageNum"></a>
				<a class="pages-jump" v-if="pageNum!=pages" @click="pageNum++">›</a>
				<a v-if="pageNum!=pages" @click="pageNum=pages">»</a>
			</li>
		</ul>

	</div>


	<script src="/scriptZIP/vue.min.js"></script>
	<script src="/scriptZIP/axios.min.js"></script>
	<script src="/scriptZIP/qs.min.js"></script>
	<script src="/scriptZIP/dayjs.min.js"></script>
	<script src="/js/common.js"></script>
	<script src="/js/list.js"></script>
	<script src="/js/auth_util.js"></script>

	<script>

		var app = new Vue(merge({
			data: {
				urls: {
					del: '/pc/device/del',
					list: '/pc/device/list'
				},
				search: {
					agentId: top_params().id,
					type: 1
				},
				schools: []
			},
			created: function () {
				this.getData();
				axios.get('/pc/school/all/' + this.search.agentId).then(function (res) {
					this.schools = res.data;
				}.bind(this));
				abled('device', this);
			},
			methods: {
				format: function (time) {
					if (!time) return '';
					return dayjs(time).format('YYYY-MM-DD HH:mm:ss');
				}
			}
		}));
	</script>
</body>

</html>